#include <iostream>
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <map>
#include <set>
#include <unordered_map>
#include <unordered_set>
#include <climits>
#include <iomanip>
#include <cmath>
#include <string>
#include <vector>
#define int long long
#define x first 
#define y second 
using namespace std;
const int N = 1e5 + 10;
//int a[N];
typedef pair<int,int> PII;
PII p[N];
unordered_map<int,vector<int>> row_mp;
unordered_map<int,vector<int>> col_mp;
void solve()
{
     int n,m;
     cin >> n >> m;
     for(int i = 1; i <= m; i++)  cin >> p[i].x >> p[i].y;

     for(auto &c : p)
     {
        int a = c.x;
        int b = c.y;
        row_mp[a].push_back(b);
        col_mp[b].push_back(a);
     }
     int len = 0;
     for(auto &c : row_mp)
     {
         if(c.y.size() > 1)
         {
           /*   int min_pos = *min_element(c.y.begin() , c.y.end());
             int max_pos = *max_element(c.y.begin() , c.y.end()); */
             sort(c.y.begin() , c.y.end());
             len = max(len , c.y[c.y.size() - 1] - c.y[0]);
         }
     }
     for(auto &c : col_mp)
     {
         if(c.y.size() > 1)
         {
            /*  int min_pos = *min_element(c.y.begin() , c.y.end());
             int max_pos = *max_element(c.y.begin() , c.y.end());
             len = max(len , max_pos - min_pos); */
               sort(c.y.begin() , c.y.end());
             len = max(len , c.y[c.y.size() - 1] - c.y[0]);
         }
     }
     cout << len << endl;
}
signed main()
{
    ios::sync_with_stdio(false);
    cin.tie(nullptr),cout.tie(nullptr);
    int t = 1;
    /*  int t;
     cin >> t; */
    while(t -- ) solve();
    return 0;
}